package com.es.hr.emp;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.es.main.LoginUserBeen;
import com.es.util.common.CommonBiz;
import com.es.util.common.ProvinceBean;
import com.es.util.format.Format;
import com.opensymphony.webwork.interceptor.ServletRequestAware;
import com.opensymphony.webwork.interceptor.ServletResponseAware;
import com.opensymphony.xwork.ActionSupport;

@SuppressWarnings("serial")
public class AjaxGetAreaListAction  extends ActionSupport implements ServletRequestAware, ServletResponseAware{
	
  HttpServletRequest request;
  HttpServletResponse response;

  public String execute() throws Exception
  {
	  CommonBiz biz = new CommonBiz((LoginUserBeen)request.getSession(false).getAttribute("loginuser"));
	  String queryAreaCode = request.getParameter("queryAreaCode").trim();
	  ArrayList<ProvinceBean> pro = biz.getProvinceList(queryAreaCode);
	  HashMap<String,List<String>> map = new HashMap<String,List<String>>();
	  List<String> list = new ArrayList<String>();
	  
	  for (ProvinceBean province : pro) {
		  list.add(province.getProvinceCode()+","+province.getProvinceName());
	  }
	  map.put("province", list);
      String returnTxt = Format.createResponseMessageAsXML(map);
      this.response.setContentType("text/xml;charset=utf-8");
      this.response.getWriter().write(returnTxt);
      return "";
  }

  public void setServletRequest(HttpServletRequest request) {
    this.request = request;
  }

  public void setServletResponse(HttpServletResponse response) {
    this.response = response;
  }
}
